2020-2021 Sunseeker Telemetry and Lighting System
ucs_ex4_XTSourcesDCOInternal.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
73 //*****************************************************************************
74 #include "driverlib.h"
75 //*****************************************************************************
76 //
77 //Desired Timeout for XT1 initialization
78 //
79 //*****************************************************************************
80 #define UCS_XT1_TIMEOUT 50000
81 
82 //*****************************************************************************
83 //
84 //Desired Timeout for XT2 initialization
85 //
86 //*****************************************************************************
87 #define UCS_XT2_TIMEOUT 50000
88 
89 //*****************************************************************************
90 //
91 //XT1 Crystal Frequency being used
92 //
93 //*****************************************************************************
94 #define UCS_XT1_CRYSTAL_FREQUENCY 32768
95 
96 //*****************************************************************************
97 //
98 //XT2 Crystal Frequency being used
99 //
100 //*****************************************************************************
101 #define UCS_XT2_CRYSTAL_FREQUENCY 24000000
102 
103 //*****************************************************************************
104 //
105 //Variable to store returned STATUS_SUCCESS or STATUS_FAIL
106 //
107 //*****************************************************************************
108 uint8_t returnValue = 0;
109 
110 //*****************************************************************************
111 //
112 //Variable to store current clock values
113 //
114 //*****************************************************************************
115 uint32_t clockValue;
116 
117 //*****************************************************************************
118 //
119 //Variable to store status of Oscillator fault flags
120 //
121 //*****************************************************************************
122 uint16_t status;
123 
124 void main (void)
125 {
126  //Stop WDT
127  WDT_A_hold(WDT_A_BASE);
128 
129  //ACLK, MCLK, SMCLk set out to pins
130  GPIO_setAsPeripheralModuleFunctionOutputPin(
131  GPIO_PORT_P11,
132  GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2
133  );
134 
135  //Port select XT1
136  GPIO_setAsPeripheralModuleFunctionInputPin(
137  GPIO_PORT_P7,
138  GPIO_PIN0 + GPIO_PIN1
139  );
140 
141  //Initializes the XT1 and XT2 crystal frequencies being used
142  UCS_setExternalClockSource(
145  );
146 
147  //Initialize XT1. Returns STATUS_SUCCESS if initializes successfully
148  returnValue = UCS_turnOnLFXT1WithTimeout(
149  UCS_XT1_DRIVE_0,
150  UCS_XCAP_3,
152  );
153 
154  //Startup HF XT2 crystal Port select XT2
155  GPIO_setAsPeripheralModuleFunctionInputPin(
156  GPIO_PORT_P5,
157  GPIO_PIN2 + GPIO_PIN3
158  );
159 
160  //Initialize XT2. Returns STATUS_SUCCESS if initializes successfully
161  returnValue = UCS_turnOnXT2WithTimeout(
162  UCS_XT2_DRIVE_4MHZ_8MHZ,
164  );
165 
166  //Select XT1 as ACLK source
167  UCS_initClockSignal(
168  UCS_ACLK,
169  UCS_XT1CLK_SELECT,
170  UCS_CLOCK_DIVIDER_1
171  );
172 
173  //Select XT2 as SMCLK source
174  UCS_initClockSignal(
175  UCS_SMCLK,
176  UCS_XT2CLK_SELECT,
177  UCS_CLOCK_DIVIDER_1
178  );
179 
180  // Enable global oscillator fault flag
181  SFR_clearInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
182  SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
183 
184  // Enable global interrupt
185  __bis_SR_register(GIE);
186 
187  //Verify if the Clock settings are as expected
188  clockValue = UCS_getMCLK();
189  clockValue = UCS_getACLK();
190  clockValue = UCS_getSMCLK();
191 
192  //Loop in place
193  while (1) ;
194 }
195 
196 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
197 #pragma vector=UNMI_VECTOR
198 __interrupt
199 #elif defined(__GNUC__)
200 __attribute__((interrupt(UNMI_VECTOR)))
201 #endif
202 void NMI_ISR(void)
203 {
204  do {
205  // If it still can't clear the oscillator fault flags after the timeout,
206  // trap and wait here.
207  status = UCS_clearAllOscFlagsWithTimeout(1000);
208  } while(status != 0);
209 }
#define UCS_XT1_CRYSTAL_FREQUENCY
void NMI_ISR(void)
#define UCS_XT2_TIMEOUT
uint16_t status
void main(void)
#define UCS_XT2_CRYSTAL_FREQUENCY
#define UCS_XT1_TIMEOUT
uint8_t returnValue
uint32_t clockValue